package priv.pattern.Mediatorpattern.service.impl;

import priv.pattern.Mediatorpattern.service.QQ;
import priv.pattern.Mediatorpattern.service.User;

import java.util.HashSet;
import java.util.Set;

/*
 * 作者：m鹏h
 * 时间；2024/8/11 10:58
 * 描述：
 **/
public class QQManager  implements QQ {
private Set<User> list = new HashSet<>();
 @Override
 public void setMessage(User from, User to, String message) {
  from.showMessage("发送"+message+"成功");
  to.showMessage("收到"+message+"成功");
 }

 @Override
 public void addUser(User user) {
list.add(user);
 }

 @Override
 public void setAllMessage(User from, String msg) {
if (!list.contains(from)) list.add(from);
from.showMessage("发送"+msg+"成功");
for (User user : list) {
 user.showMessage("接收"+msg+"成功");
}
 }
}
